<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Integrating libgutenprint</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="The Developer's Guide to Gutenprint"
HREF="book1.html"><LINK
REL="UP"
TITLE="Using libgutenprint"
HREF="c48.html"><LINK
REL="PREVIOUS"
TITLE="Linking with libgutenprint"
HREF="x67.html"><LINK
REL="NEXT"
TITLE="Reporting Bugs"
HREF="c194.html"><META
http-equiv="Content-Type"
content="text/html; charset=@encoding@"></HEAD
><BODY
CLASS="sect1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The Developer's Guide to Gutenprint</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x67.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 2. Using libgutenprint</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="c194.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="AEN79"
>Integrating libgutenprint</A
></H1
><P
>&#13;      This section describes how to integrate the compiling and
      linking of programs using libgutenprint with build
      scripts. Commonly used systems include <B
CLASS="command"
>make</B
>,
      but often <TT
CLASS="filename"
>Makefile</TT
> files are generated by
      using tools such as <B
CLASS="command"
>autoconf</B
> and
      <B
CLASS="command"
>automake</B
>.
    </P
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN86"
><B
CLASS="command"
>pkg-config</B
></A
></H2
><P
>&#13;	Depending on the nature of the computer system Gutenprint was
	installed on, as well as the options passed to
	<B
CLASS="command"
>configure</B
> when configuring the package when
	it was built, the <CODE
CLASS="varname"
>CFLAGS</CODE
> and
	<CODE
CLASS="varname"
>LIBS</CODE
> parameters needed to compile and link
	programs with libgutenprint may vary.  To make it simple to
	determine what these are on any given system, a
	<B
CLASS="command"
>pkg-config</B
> datafile was created when
	Gutenprint was built.  <B
CLASS="command"
>pkg-config</B
> will
	output the correct parameters for the setup on your system.
	See the
	<SPAN
CLASS="citerefentry"
><SPAN
CLASS="refentrytitle"
>pkg-config(1)</SPAN
></SPAN
> manual page for a compete synopsis.
      </P
><P
>&#13;	The correct <CODE
CLASS="varname"
>CFLAGS</CODE
> to use can be obtained
	with the <CODE
CLASS="option"
>--cflags</CODE
> option:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>pkg-config --cflags gutenprint</KBD
>
-I/usr/local/include</PRE
></TD
></TR
></TABLE
><P
>&#13;	The correct <CODE
CLASS="varname"
>LIBS</CODE
> to use can the obtained
	with the <CODE
CLASS="option"
>--libs</CODE
> option:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>pkg-config --libs gutenprint</KBD
>
-L/usr/local/lib -lgutenprint -lm -ldl</PRE
></TD
></TR
></TABLE
><P
>&#13;        Lastly, the installed version of Gutenprint can be obtained with the
	<CODE
CLASS="varname"
>--version</CODE
> option:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>pkg-config --modversion gutenprint</KBD
>
4.3.23</PRE
></TD
></TR
></TABLE
><P
>&#13;	The command can be used from the shell by enclosing it in
	backquotes ‘`’:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
><SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>gcc `pkg-config --cflags gutenprint` -c stpimage.c</KBD
>
<SAMP
CLASS="prompt"
>$</SAMP
> <KBD
CLASS="userinput"
>gcc `pkg-config --libs gutenprint` -o
  stpimage stpimage.o</KBD
></PRE
></TD
></TR
></TABLE
><P
>&#13;	However, this is not the way it it typically used. Normally
	it is used in a <TT
CLASS="filename"
>Makefile</TT
> or by an m4
	macro in a <B
CLASS="command"
>configure</B
> script.
      </P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN123"
><B
CLASS="command"
>make</B
></A
></H2
><P
>&#13;	If you use <B
CLASS="command"
>make</B
> with your own
	<TT
CLASS="filename"
>Makefile</TT
> files, then you are on your
	own. This manual offers no assistance with doing this. Only
	the following suggestion is offered, for use with GNU
	<B
CLASS="command"
>make</B
>:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>GUTENPRINT_VERSION = $(shell pkg-config --version gutenprint)
GUTENPRINT_CFLAGS = $(shell pkg-config --cflags gutenprint)
GUTENPRINT_LIBS = $(shell pkg-config --libs gutenprint)</PRE
></TD
></TR
></TABLE
><P
>&#13;	How you choose to use these variables is entirely up to
	you. See the GNU <B
CLASS="command"
>make</B
> manual for more
	information.
      </P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN133"
><B
CLASS="command"
>autoconf</B
></A
></H2
><P
>&#13;	The <B
CLASS="command"
>autoconf</B
> program produces a Bourne
	shell script called <TT
CLASS="filename"
>configure</TT
> from a
	template file called <TT
CLASS="filename"
>configure.ac</TT
>.
	<TT
CLASS="filename"
>configure.ac</TT
> contains both Bourne shell
	script, and m4 macros.  <B
CLASS="command"
>autoconf</B
> expands
	the m4 macros into ‘real’ shell script.  The
	resulting <B
CLASS="command"
>configure</B
> script performs various
	checks for installed programs, compiler characteristics and
	other system information such as available headers and
	libraries.  See the GNU <B
CLASS="command"
>autoconf</B
> manual for
	more information.
      </P
><P
>&#13;	<B
CLASS="command"
>pkg-config</B
> provides an m4 macro,
	<CODE
CLASS="function"
>PKG_CHECK_MODULES</CODE
>, suitable for use in a
	<TT
CLASS="filename"
>configure.ac</TT
> script.  It defines the
	environment variables required for building libgutenprint-based
	programs.  For example, to set GUTENPRINT_CFLAGS and
	GUTENPRINT_LIBS:
      </P
><DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN148"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>PKG_CHECK_MODULES(GUTENPRINT, gutenprint)</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN150"
><B
CLASS="command"
>automake</B
></A
></H2
><P
>&#13;	The <B
CLASS="command"
>automake</B
> program can be used to
	generate <TT
CLASS="filename"
>Makefile.in</TT
> files suitable for
	use with a <TT
CLASS="filename"
>configure</TT
> script generated by
	<B
CLASS="command"
>autoconf</B
>.  As <B
CLASS="command"
>automake</B
>
	<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>requires</I
></SPAN
> <B
CLASS="command"
>autoconf</B
>,
	this section will assume the use of a
	<TT
CLASS="filename"
>configure.ac</TT
> script which uses the
	<CODE
CLASS="function"
>PKG_CHECK_MODULES</CODE
> macro described above
	(there is little point in <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>not</I
></SPAN
> using it!).
      </P
><P
>&#13;        It is highly recommended that you use GNU
	<B
CLASS="command"
>autoconf</B
> and
	<B
CLASS="command"
>automake</B
>. They will allow you to make your
	software build on most platforms with most compilers.
	<B
CLASS="command"
>automake</B
> makes writing complex
	<TT
CLASS="filename"
>Makefile</TT
>'s very easy, by expressing how
	to build your packages in terms of what files are required to
	build a project and the installation locations of the files.
	It imposes a few limitations over using plain
	<TT
CLASS="filename"
>Makefile</TT
>'s, such as in the use of
	conditionals, but these problems are vastly outweighed by the
	benefits it brings.  It also creates many extra targets in the
	generated <TT
CLASS="filename"
>Makefile.in</TT
> files such as
	<CODE
CLASS="option"
>dist</CODE
>, <CODE
CLASS="option"
>distcheck</CODE
>,
	<CODE
CLASS="option"
>clean</CODE
>, <CODE
CLASS="option"
>distclean</CODE
>,
	<CODE
CLASS="option"
>maintainer-clean</CODE
> and <CODE
CLASS="option"
>tags</CODE
>,
	and there are many more more available.  See the GNU
	<B
CLASS="command"
>automake</B
> manual for more information.
      </P
><P
>&#13;	Because <CODE
CLASS="function"
>PKG_CHECK_MODULES</CODE
> calls
	<CODE
CLASS="function"
>AC_SUBST</CODE
> to substitute
	<CODE
CLASS="varname"
>GUTENPRINT_CFLAGS</CODE
> and
	<CODE
CLASS="varname"
>GUTENPRINT_LIBS</CODE
>, <B
CLASS="command"
>automake</B
>
	will automatically set these variables in the
	<TT
CLASS="filename"
>Makefile.in</TT
> files it generates, requiring
	no additional effort on your part!
      </P
><P
>&#13;	As in previous examples, we will make a program
	<B
CLASS="command"
>stpimage</B
> from
	<TT
CLASS="filename"
>stpimage.c</TT
>.  This is how one might build
	write a <TT
CLASS="filename"
>Makefile.am</TT
> to do this:
      </P
><DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN189"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>@SET_MAKE@

AM_CFLAGS = $(GUTENPRINT_CFLAGS)

bin_PROGRAMS = stpimage
stpimage_SOURCES = stpimage.c
stpimage_LDADD = $(GUTENPRINT_LIBS)

MAINTAINERCLEANFILES = Makefile.in</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>&#13;        That's all there is to it!  Please note that this example also
	requires the macro <CODE
CLASS="function"
>AC_PROG_MAKE_SET</CODE
> to be
	used in <TT
CLASS="filename"
>configure.ac</TT
>.
      </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x67.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="c194.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Linking with libgutenprint</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c48.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Reporting Bugs</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>